package starter;

import ggt.Koordinator;
import ggt.KoordinatorHelper;
import ggt.Starter;
import ggt.StarterHelper;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;


public class StarterServer {
    
	public static void main(String[] args) {
        try {
            // ORB Eigenschaften setzen
            ORB orb = ORB.init(args, null);

            // Referenz von rootPOA holen und POA Manager aktivieren
            POA rootPoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
            rootPoa.the_POAManager().activate();

            // Referenz zum Namensdiesnt (root naming context) holen
            NamingContextExt nameservice = NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
            
            //Referenz vom Koordinator vom Namensdienst holen
            org.omg.CORBA.Object obj = nameservice.resolve_str(args[4]);
            Koordinator koor = KoordinatorHelper.narrow(obj);
            
            @SuppressWarnings("unused")
			Starter starter = StarterHelper.narrow(
                    rootPoa.servant_to_reference(new StarterImpl(args[5], koor, orb)));
           
            System.out.printf("Starter %s bereit\n", args[5]);
            orb.run();

        } catch (Exception e) {
            System.err.println("ERROR: " + e);
            e.printStackTrace(System.out);
        }
    }
}
